package com.example.bootintegration.dao.test.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import java.util.List;

/**
 * @author Quintoy
 * @date 12/28/22
 */
@Service
public class StudentService {

    @Autowired
    private ApplicationContext context;

    public void save() {
        EntityManager targetObject = (EntityManager) context.getBean("testEntityManager");
//        String repositoryBeanName = beanNamesForType[0].replaceAll("Impl$", "");
        EntityManager entityManager = targetObject.unwrap(null);
        System.out.println(entityManager);
        Query nativeQuery = entityManager.createNativeQuery("select * from student");
        List resultList = nativeQuery.getResultList();
        System.out.println(resultList);
    }

    public EntityManager getTargetEntityManager() {
        return null;
    }
}
